<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .uu {
            display: flex;
            margin: 0;
            height: 40px;
            justify-content: space-around;
            padding: 0;
            width: 190px;
            align-items: center;
        }

        li {
            list-style: none;
            width: 20%;

            height: 100%;
        }

        .color {
            padding: 5%;
            background-color: white !important;
            box-sizing: border-box;
            border: 9px solid red;
        }

        #tab {
            width: 500px;
            text-align: center;
        }

        #tab td {
            border: 1px solid black;
        }
    </style>
</head>

<body>
    <ul class="uu">
        <li name='红色'></li>
        <li name='绿色'></li>
        <li name='黑色'></li>
    </ul>
    <table id="tab">
        <tr>
            <td>新闻</td>
            <td>娱乐</td>
            <td>体育</td>
            <td>电影</td>
            <td>音乐</td>
            <td>旅游</td>
        </tr>
    </table>
</body>
<script>
    let lis = document.getElementsByTagName('li')

    let tab = document.getElementById('tab')
    let tds = tab.getElementsByTagName('td')
    console.log(tds);
    lis[0].style.backgroundColor = 'red'
    lis[1].style.backgroundColor = '#008000'
    lis[2].style.backgroundColor = '#000000'
    for (let i = 0; i < lis.length; i++) {
        lis[i].onclick = function () {
            for (let x = 0; x < lis.length; x++) {
                lis[x].className = ''
            }
            this.className = 'color'
            if (this.getAttribute('name') == '红色') {
                document.body.style.backgroundColor = '#ff0076'
                for (let p = 0; p < tds.length; p++) {
                    tds[p].style.backgroundColor = 'red'
                    tds[p].style.color = '#008000'
                    tds[p].style.border = '1px solid #008000'
                }
            } else if (this.getAttribute('name') == '绿色') {
                document.body.style.backgroundColor = '#718000'

            } else if (this.getAttribute('name') == '黑色') {
                document.body.style.backgroundColor = '#cccccc'
                for (let p = 0; p < tds.length; p++) {
                    tds[p].style.backgroundColor = '#000000'
                    tds[p].style.color = '#008000'
                    tds[p].style.border = '1px solid #008000'
                }
            }
        }
    }
</script>

</html>